package com.guli.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

//订单确认页需要的数据
public class OrderConfirmVo {
    //收货地址
    @Getter
    @Setter
    List<MemberAddressVo> address;
    //所有选中的购物项
    @Getter
    @Setter
    List<OrderItemVo> items;
    //发票

    //优惠券信息
    /**
     * 积分
     */
    @Getter
    @Setter
    private Integer integration;
    /**
     * 是否有库存
     */
    @Getter
    @Setter
    Map<Long,Boolean> stocks;

    /**
     * token防止重复提交,幂等
     * @return
     */
    @Getter
    @Setter
    String orderToken;

    public Integer getCount(){
        Integer i = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }

    //订单总额
//    BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //应付总额
//    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
